<?php

unset($footer);
$inactivitymin=$configarray[13]/60;
$onlinearray=getdata("$configarray[1]/online.php");
$onlineguestcount=0;
$onlineusercount=0;
$count=count($onlinearray);


//find old entries and delete
for($n=0;$n<$count;$n++){
	
	if(substr($onlinearray[$n],0,9)=="guestsess"){
		//its a guest
		
		if(substr($onlinearray[$n+1],0,9)=="guesttime"){
			//make sure there is second line for guest also	
			$time=$globaltime;
		
			//if guest last activity is less than '$configarray[13]' seconds ago
			//substr gets timestamp from guest listing first 5 chars is "Guest" rest is timestamp
			if(($time-$configarray[13])<substr($onlinearray[$n+1],9)){
				$onlineguestcount++;
				//loop already goes up 1 line each time but guest listing is 2 lines
				$n++;
			}else{			
				//expired and needs to be deleted
				deletedata("$configarray[1]/online.php",$n);
				//2nd line moves up into first ones spot so delete with same line number
				deletedata("$configarray[1]/online.php",$n);
				//get new online array with lines deleted
				$onlinearray=getdata("$configarray[1]/online.php");
				//3rd line moves up, subtract 1 count to make sure it gets checked
				$n--;
				$count-=2; //2 less items now	
			}
			
		}else{
			//invalid guest entry
			deletedata("$configarray[1]/online.php",$n);
			$count--; //1 less items now
		}
		
	}elseif(substr($onlinearray[$n],0,4)=="user"){
		//its a user
		$userarray=getdata("$configarray[1]/".substr($onlinearray[$n],4)."/main.php",0);
		$lastloginarray=explode("\t",$userarray[5]);
		$time=$globaltime;
		
		//user exists
		if(count($userarray)>0){
		
			//if user last activity is less than '$configarray[13]' seconds ago
			if(($time-$configarray[13])<$lastloginarray[1]){
				$onlineusercount++;
				if($userarray[15]=="administrator"){
					$onlineusers=$onlineusers . "<a href=\"profile.php?user=".substr($onlinearray[$n],4)."\"><b>$userarray[0]</b></a>&nbsp&nbsp";
				}else{
					$onlineusers=$onlineusers . "<a href=\"profile.php?user=".substr($onlinearray[$n],4)."\">$userarray[0]</a>&nbsp&nbsp";
				}
			}else{
			
				deletedata("$configarray[1]/online.php",$n);
				//2nd line moves up, subtract 1 count to make sure it gets checked
				$n--;
				$count--; //1 less items now
			
			}
		
		}else{
			deletedata("$configarray[1]/online.php",$n);
			$count--; //1 less items now
		}
		
		
	}else{
		//invalid online list entry
		deletedata("$configarray[1]/online.php",$n);
		$count--; //1 less items now
	}
	
}//end online loop


$onlinetotal=$onlineguestcount+$onlineusercount;
$footer['onlinetotal']=$onlinetotal;
$footer['onlinemin']=$inactivitymin;
$footer['onlineguests']=$onlineguestcount;
$footer['onlineusers']=$onlineusercount;
$footer['onlinelist']=$onlineusers;

if($login==1&&$userloggedinoptarray[0]!=="on"){
	
	$pmsarray=listfiles("$configarray[1]/$useridarray[$navboardlogin]/pms");
	for($n=0;$n<count($pmsarray);$n++){
		$pmarray=getdata("$configarray[1]/$useridarray[$navboardlogin]/pms/$pmsarray[$n].php");
		if($pmarray[8]=="unread"){
			$footer['newpms']=$languagedef['newmessages']." <a href=\"user_pm.php\">".$languagedef['inbox']."</a>!";
			break 1;
		}
	}
}


$footer['navigationformheader']="
	<form action=\"index.php\" method=get>";

$footer['navigation']="
	<select size=1 onchange=\"window.location=(this.options[this.selectedIndex].value)\" class=\"forminput\">
	<option value=\"\"></option>

	<option value=\"index.php\">".$languagedef[2]."</option>
	<option value=\"register.php\">".$languagedef[3]."</option>";
	
if($login==1){
	$footer['navigation'].="<option value=\"\">--------------</option>".
	"<option value=\"user_edit.php\">".$languagedef[4]."</option>".
	"<option value=\"user_pm.php\">".$languagedef[5]."</option>".
	"<option value=\"user_buddy.php\">".$languagedef[6]."</option>";
}
$footer['navigation'].="<option value=\"\">--------------</option>";

for($n=0;$n<count($modulesarray);$n++){
	$footer['navigation'].="<option value=\"modules.php?module=$modulesarray[$n]\">$modulesarray[$n]</option>";
}
$footer['navigation'].="<option value=\"\">--------------</option>";

forumsfootermenu("0",0);

$footer['navigation'].="</select>";

$footer['navigationformfooter'].="</form>";

if($login>1){
	$loginerror=array("","",$languagedef['nosuchuser'],$languagedef['youareban'],$languagedef['invalidpass'],$languagedef['acctnotactiv']);
	$footer['login'].="<i>$loginerror[$login]</i>";
}

if($login==1){
	unset($tplcontent2);
	$tplcontent2['account'].=$navboardlogin;
	$tplcontent2['display'].=$userloggedinarray[0];
    $tplcontent2['logout'].="<a href=index.php?logout=1>".$languagedef[339]."</a>";
    $footer['login'].=template('footerloginstatus',$tplcontent2);
}

if($login!==1){
	unset($tplcontent2);
	$tplcontent2['loginformheader'].="<form action=\"index.php\" method=post><input type=hidden name=\"loggingin\" value=1>";
	$tplcontent2['loginusername'].="<input type=text name=\"navboardlogin2\" size=10 class=\"forminput\">";
	$tplcontent2['loginpassword'].="<input type=password name=\"navboardpass2\" size=10 class=\"forminput\">";
	$tplcontent2['loginrememberme'].="<input type=checkbox name=\"rememberme\" class=\"forminput\">";
	$tplcontent2['loginsubmitbutton'].="<input type=submit name=\"submit\" value=\"Login!\" class=\"formbutton\">";
	$tplcontent2['loginformfooter'].="</form>";
	$footer['login'].=template('footerloginform',$tplcontent2);
}

$footer['credits']="<a href=\"http://navarone.f2o.org\">NavBoard</a> 2.7.0 dev build 05/23/2004";


$footer['contact']="< ";
if($configarray[35]){
	$footer['contact'].="<a href=\"mailto:$configarray[35]\">".$languagedef[1]."</a> "."-";
}
$footer['contact'].=" <a href=\"$configarray[36]\">".$languagedef[0]."</a>"." >";

//START FOOTER STATS

if($userloggedinoptarray[2]!=="on"){
	//TOTAL POST COUNT START
	
	for($m=0;$m<count($forumarray);$m++){
		$forumconfigarray=getdata("$configarray[2]/$forumarray[$m].php");
		
		if($forumconfigarray[5]!=="category"){//dont scan categories
			$topicarray=listdirs("$configarray[2]/$forumarray[$m]");
			$totaltopics+=count($topicarray);
		
			if($configarray[42]=="on"){
				$totalposts+=$forumconfigarray[11];
			}else{
				for($n=0;$n<count($topicarray);$n++){
					$postarray=listfiles("$configarray[2]/$forumarray[$m]/$topicarray[$n]");
					$totalposts+=count($postarray)-1;
				}
			}//real time disable check
		}//dont scan categories check
	}//forum loop
	//END TOTALPOSTCOUNT
	$totaloverallposts=$totaltopics+$totalposts;
}

$totalusers=count($usersarray);

if(count($usersarray)>0){
	@rsort($usersarray);
	$userarray=getdata("$configarray[1]/$usersarray[0]/main.php");
	$footer['statsnewmember']="<a href=\"profile.php?user=$usersarray[0]\">$userarray[0]</a>";
}else{
	$footer['statsnewmember']="None";
}

$footer['statsmembers'].=$totalusers;

if($userloggedinoptarray[2]!=="on"){
	$footer['statstopics'].=$totaltopics;
	$footer['statsreplies'].=$totalposts;
	$footer['statstotal'].=$totaloverallposts;
}else{	
	$footer['statstopics'].="N/A";
	$footer['statsreplies'].="N/A";
	$footer['statstotal'].="N/A";	
}
//END FOOTER STATS

//end footer vars

print template("footer",$footer);

print "</td>";
print "</tr>";

print "</table>";

print "</body>\n";
print "</html>\n";

print "<span class=\"textsmall\">";
print "<p align=center>";
print "[ Files queried: ${filesopened} | Files queried from cache: ${filesopenedcached} | Directories queried: ${dirsread} | Directories queried from cache: ${dirsreadcached} | File writes: $filewrites | Templates used: $tplused | Cache templates used: $tplusedcache | <a href=\"cvs.php\">CVS</a> ]";
print "</p>";
print "</span>";

@ob_end_flush();

?>
